package javaStuff;
import java.sql.*;
public class JDBCCallable{
	
	Connection conn = null ;
	
    public JDBCCallable(){
        String connectionURL = Login.DRIVER + Login.DB;
        
        try {
            Class.forName (Login.DRIVER_CLASS); 
            System .out.println ("Attempting connection to " 
                    + connectionURL );
            conn = DriverManager.getConnection 
                    (connectionURL,Login.USER,Login.PWD );
            System.out.println ("Connection successful ");

            /*callableStatement.setDouble(1, price);
            callableStatement.setInt(2, greaterThan);
            
            callableStatement.registerOutParameter
                        (3, java.sql.Types.INTEGER);
            callableStatement.registerOutParameter
                        (4, java.sql.Types.DOUBLE);*/
 
            // execute store procedure
            
            
            /*System .out.println ("Results:");
            while (results.next ()){
                String name = results.getString ("name");
                String id = results.getString ("id");
                //price =   results.getDouble ("price");
                System.out. println 
                    ("Name = " + name + ", ID = " + id);
            }
            
            /*int  total = callableStatement.getInt(3);
            double bounds = callableStatement.getDouble(4);
            System.out. println
                ("Total rows="+total+", bounds = "+bounds);*/
            
            
        }
        catch ( Exception e) { 
            System .out.println (" Error " + e );
        }
    }
    
    public  int userExists(String user_name,String password)
    {
    	try
    	{
    		String storedProc = "select user_name,password,level_of_access from users where user_name='" + user_name + "'" + " and password='" + password +"'" + ";";
            CallableStatement callableStatement = conn.prepareCall(storedProc);
            callableStatement.clearParameters(); 
            ResultSet results = callableStatement.executeQuery();
            results.next();
            int access = results.getInt("level_of_access");
            callableStatement.close ();
            return access;
    	}
    	catch(Exception E)
    	{
    		return -1;
    	}
    }
    
    public void close()
    {
    	 try {
			conn.close ();
			System.out.println("closed");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}